package org.zjkoye.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.zjkoye.crm.entity.Region;
import org.zjkoye.crm.mapper.RegionMapper;
import org.zjkoye.crm.service.RegionService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zjkoye
 * @since 2024-06-23
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements RegionService {

    @Override
    public IPage<Region> pageList(int pageSize, int currentPage, String name) {
        LambdaQueryWrapper<Region> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null && !name.isEmpty()) {
            queryWrapper.like(Region::getRegionName, name);
        }
        Page<Region> page = new Page<>(currentPage, pageSize);
        return this.page(page, queryWrapper);
    }

    @Override
    public boolean isExist(String name) {
        LambdaQueryWrapper<Region> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Region::getRegionName, name);
        long count = this.count(queryWrapper);
        return count > 0;
    }
}
